<template>
  <a-card :bordered="false" class="goods_list_add">
    <el-page-header @back="$router.go(-1)" style="margin-bottom:10px"></el-page-header>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      :labelWidth="labelWidth"
      class="demo-ruleForm"
    >
      <!-- 基本信息 -->
      <com-title :styleIng="{margin:'10px 0px 10px 10px'}" :isShow="false">
        <span slot="title">基本信息</span>
        <el-row :gutter="10" slot="table">
          <el-col :xs="8">
            <el-form-item label="供应商名称：" prop="gysmc">
              <a-select v-model="ruleForm.gysmc" placeholder="请选择供应商名称" :disabled="disabled">
                <a-select-option
                  :value="item.value"
                  v-for="(item,index) in gysmc"
                  :key="index"
                >{{item.label}}</a-select-option>
              </a-select>
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="商品名称：" prop="spmc">
              <a-input v-model="ruleForm.spmc" placeholder="请输入商品名称，不超过30个字符" :disabled="disabled" />
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="商品条码：" required>
              <el-col :span="4">
                <el-form-item prop="sptm">
                  <a-select v-model="ruleForm.sptm" @change="sptmChange" :disabled="disabled">
                    <a-select-option :value="0">无</a-select-option>
                    <a-select-option :value="1">有</a-select-option>
                  </a-select>
                </el-form-item>
              </el-col>
              <el-col :span="20" style="padding-right:0">
                <el-form-item prop="sptm1">
                  <a-input
                    v-model="ruleForm.sptm1"
                    placeholder="请输入商品条码"
                    v-show="sptmPlaceholder"
                    :disabled="disabled"
                  />
                </el-form-item>
              </el-col>
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="商品类目：" prop="splm">
              <a-select v-model="ruleForm.splm" placeholder="请选择商品类目" :disabled="disabled">
                <a-select-option
                  :value="item.value"
                  v-for="(item,index) in gysmc"
                  :key="index"
                >{{item.label}}</a-select-option>
              </a-select>
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="商品类型：" prop="splx">
              <a-select v-model="ruleForm.splx" placeholder="请选择供应商名称" :disabled="disabled">
                <a-select-option
                  :value="item.value"
                  v-for="(item,index) in gysmc"
                  :key="index"
                >{{item.label}}</a-select-option>
              </a-select>
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="商品图片：">
              <div class="upload_list clearfix">
                <div :key="item.uid" v-for="item in fileList">
                  <el-image class="imgs" :src="item.url" alt :preview-src-list="fileListUrl"></el-image>
                  <div>
                    <a-button type="link" size="small" @click="setZhutu(item)" v-if="false">设为主图</a-button>
                    <a-button type="link" size="small" style="color:#000" v-else>主图</a-button>
                    <a-button type="link" size="small" @click="delUplod(item)">删除</a-button>
                  </div>
                </div>
                <a-upload
                  name="avatar"
                  listType="picture-card"
                  class="avatar-uploader"
                  :showUploadList="false"
                  :beforeUpload="beforeUpload"
                  @change="handleChange"
                  :disabled="disabled"
                >
                  <div v-if="fileList.length < 6">
                    <a-icon :type="loading ? 'loading' : 'plus'" />
                    <div class="ant-upload-text">点击上传</div>
                  </div>
                </a-upload>
              </div>
              <!-- modal -->
              <cropper-modal
                ref="cropperModal"
                :optionsData="optionsData"
                @ok="handleCropperSuccess"
              ></cropper-modal>
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="商品描述：" prop="spms">
              <a-input
                v-model="ruleForm.spmc"
                placeholder="请填写商品描述"
                type="textarea"
                :disabled="disabled"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="8" v-if="sptmPlaceholder">
            <el-form-item label="库存单位：" prop="ccdw">
              <a-select v-model="ruleForm.ccdw" placeholder="请选择库存单位">
                <a-select-option
                  :value="item.value"
                  v-for="(item,index) in gysmc"
                  :key="index"
                  :disabled="disabled"
                >{{item.label}}</a-select-option>
              </a-select>
            </el-form-item>
          </el-col>
          <el-col :xs="8" v-if="sptmPlaceholder">
            <el-form-item label="库存换算：">
              <div v-for="(domain, index) in ruleForm.kchs" :key="index">
                <el-col :span="5">
                  <el-form-item>
                    <a-input-number
                      id="inputNumber"
                      v-model="domain.number"
                      :min="1"
                      style="width:100%"
                      :disabled="disabled"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="5" style="padding-right:0">
                  <el-form-item>
                    <a-select v-model="domain.dw" :disabled="disabled">
                      <a-select-option :value="0">箱</a-select-option>
                      <a-select-option :value="1">瓶</a-select-option>
                    </a-select>
                  </el-form-item>
                </el-col>
                <el-col :span="1" style="padding-right:0;text-align:center">=</el-col>
                <el-col :span="5" style="padding-right:0">
                  <el-form-item prop="sptm1">
                    <a-input-number
                      id="inputNumber"
                      v-model="domain.number1"
                      :min="1"
                      style="width:100%"
                      :disabled="disabled"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="4">
                  <el-form-item prop="sptm">
                    <a-select v-model="domain.dw1" :disabled="disabled">
                      <a-select-option :value="0">箱</a-select-option>
                      <a-select-option :value="1">瓶</a-select-option>
                    </a-select>
                  </el-form-item>
                </el-col>
                <el-col :span="4">
                  <el-form-item prop="sptm">
                    <a-button
                      type="link"
                      html-type="submit"
                      @click="addKchs('ruleForm')"
                      v-if="ruleForm.kchs.length == index+1 && ruleForm.kchs.length < 3"
                    >新增</a-button>
                    <a-button
                      type="link"
                      html-type="submit"
                      @click="editKchs(domain)"
                      v-if="ruleForm.kchs.length>1"
                    >删除</a-button>
                  </el-form-item>
                </el-col>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
      </com-title>
      <!-- 销售信息 -->
      <com-title :styleIng="{margin:'10px 0px 10px 10px'}" :isShow="false" v-if="sptmPlaceholder">
        <span slot="title">销售信息</span>
        <el-row :gutter="10" slot="table">
          <el-col :xs="8">
            <el-form-item label="销售价：" prop="xsj">
              <a-input
                v-model="ruleForm.xsj"
                type="number"
                addon-after="元"
                @blur="toDecimalBlur('xsj')"
                :disabled="disabled"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="成本价：" prop="cbj">
              <a-input
                v-model="ruleForm.cbj"
                type="number"
                addon-after="元"
                @blur="toDecimalBlur('cbj')"
                :disabled="disabled"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="库存数量：" prop="kcsl">
              <a-input
                v-model="ruleForm.kcsl"
                placeholder="请输入请输入大于0的整数"
                :min="0"
                @blur="toDecimalBlur('kcsl')"
                v-if="ruleForm.kcsl && soldOut"
                :disabled="disabled"
              />
              <span v-else>已售罄</span>
            </el-form-item>
          </el-col>
        </el-row>
      </com-title>

      <!-- 商品规格 -->
      <com-title :styleIng="{margin:'10px 0px 10px 10px'}" :isShow="false" v-if="sptmPlaceholder">
        <span slot="title">商品规格</span>
        <el-row :gutter="10" slot="table">
          <el-col :xs="8">
            <el-form-item label="温度：" prop="wd">
              <a-checkbox-group v-model="ruleForm.wd" :disabled="disabled">
                <a-checkbox :value="i.value" v-for="i in wdList" :key="i.value">{{i.label}}</a-checkbox>
              </a-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="糖度：" prop="td">
              <a-checkbox-group v-model="ruleForm.td" :disabled="disabled">
                <a-checkbox :value="i.value" v-for="i in tdList" :key="i.value">{{i.label}}</a-checkbox>
              </a-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
      </com-title>

      <!-- 商品参数 -->
      <com-title :styleIng="{margin:'10px 0px 10px 10px'}" :isShow="false" v-if="sptmPlaceholder">
        <span slot="title">商品参数</span>
        <el-row :gutter="10" slot="table">
          <el-col :xs="8">
            <el-form-item label="产地：" prop="cd">
              <a-input v-model="ruleForm.cd" :disabled="disabled" />
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="材质：" prop="cz">
              <a-input v-model="ruleForm.cz" :disabled="disabled" />
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="风格：" prop="tq">
              <a-radio-group v-model="ruleForm.tq" :disabled="disabled">
                <a-radio :value="i.value" v-for="i in tqList" :key="i.value">{{i.label}}</a-radio>
              </a-radio-group>
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="版型：" prop="jj">
              <a-checkbox-group v-model="ruleForm.jj" :disabled="disabled">
                <a-checkbox :value="i.value" v-for="i in jjList" :key="i.value">{{i.label}}</a-checkbox>
              </a-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
      </com-title>

      <!-- 销售渠道 -->
      <com-title :styleIng="{margin:'10px 0px 10px 10px'}" :isShow="false">
        <span slot="title">销售渠道</span>
        <el-row :gutter="10" slot="table">
          <el-col :xs="8">
            <el-form-item label="是否门店商品：" prop="mdsp">
              <a-radio-group v-model="ruleForm.mdsp" :disabled="disabled">
                <a-radio :value="0">否</a-radio>
                <a-radio :value="1">是</a-radio>
                <span
                  style="color:#ff4d4f"
                >默认选择否，则商品为公共商品支持在多个门店售卖，默认选择全部门店 如选择是，则表示此商品为特殊的门店商品只能在某个门店售卖。</span>
              </a-radio-group>
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="销售渠道：" prop="mdsp" v-if="sptmPlaceholder">
              <a-radio-group v-model="ruleForm.xsqd" :disabled="disabled">
                <a-radio :value="0">全部渠道</a-radio>
                <a-radio :value="1">仅限上</a-radio>
                <a-radio :value="3">仅限下</a-radio>
              </a-radio-group>
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="选择门店：">
              <el-cascader
                :options="mendianList"
                v-model="ruleForm.mendian"
                :props="{multiple:true}"
                clearable
                style="width:100%"
              ></el-cascader>
            </el-form-item>
          </el-col>
        </el-row>
      </com-title>

      <!-- 销售设置 -->
      <com-title :styleIng="{margin:'10px 0px 10px 10px'}" :isShow="false" v-if="sptmPlaceholder">
        <span slot="title">销售设置</span>
        <el-row :gutter="10" slot="table">
          <el-col :xs="8">
            <el-form-item label="是否促销商品：" prop="cxsp">
              <a-radio-group v-model="ruleForm.cxsp" :disabled="disabled">
                <a-radio :value="0">否</a-radio>
                <a-radio :value="1">是</a-radio>
                <span style="color:#ff4d4f">
                  默认选择否，则商品为销售价售卖；
                  如选择是，则表示此商品在促销时间内以促销价格售卖。
                </span>
              </a-radio-group>
            </el-form-item>
          </el-col>
          <el-col :xs="8">
            <el-form-item label="促销时间：">
              <a-range-picker
                v-model="ruleForm.cxsj"
                :disabled="disabled"
                show-time
                style="width:100%"
                format="YYYY-MM-DD HH:mm:ss"
                @change="cxsjChange"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </com-title>

      <!-- 商品详情 -->
      <com-title :styleIng="{margin:'10px 0px 10px 10px'}" :isShow="false" v-if="sptmPlaceholder">
        <span slot="title">商品详情</span>
        <el-row :gutter="10" slot="table">
          <el-col :xs="8">
            <el-form-item label="商品详情：" prop="spxq">
              <QuillEditor
                :value="ruleForm.spxq"
                :myQuillEditor="'myQuillEditor'"
                @editorChange="editorChange"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </com-title>
      <div class="content">
        <a-button type="primary" @click="submitSave('ruleForm')">提交并保存</a-button>
        <a-button @click="save('ruleForm')">保存</a-button>
        <a-button @click="quxiao('ruleForm')">取消</a-button>
      </div>
    </el-form>
  </a-card>
</template>

<script src='./goods_list_add.js'></script>

<style lang="less">
.goods_list_add {
  .avatar-uploader > .ant-upload {
    width: 150px;
    height: 150px;
  }
  .ant-upload-select-picture-card i {
    font-size: 32px;
    color: #999;
  }

  .ant-upload-select-picture-card .ant-upload-text {
    margin-top: 8px;
    color: #666;
  }
  .upload_list {
    & > div {
      float: left;
      margin-right: 10px;
      & > .imgs {
        width: 150px;
        height: 130px;
        border-top-left-radius: 4px;
        border-top-right-radius: 4px;
      }
      & > div {
        width: 150px;
        margin-bottom: 0;
        text-align: center;
        background-color: #fafafa;
        display: flex;
        justify-content: center;

        span {
          padding-right: 10px;
          cursor: pointer;
        }
      }
    }
    .avatar-uploader {
      float: left;
    }
  }
  .content {
    text-align: center;
    margin: 20px 0px;
    button {
      margin-right: 10px;
    }
  }
}
</style>
